package p270jp.pxv.android.activity;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;
import androidx.databinding.DataBindingUtil;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import p014ae.AbstractActivityC0120m2;
import p014ae.View$OnKeyListenerC0136p6;
import p046bf.PixivAppUserAgents;
import p047bg.C1124a;
import p090d0.C2518n;
import p134ei.AnalyticsAction;
import p134ei.AnalyticsScreenName;
import p270jp.pxv.android.R;
import p270jp.pxv.android.model.Pixivision;
import p307l9.EdgeTreatment;
import p314lg.ActivityPixivisionRenewalBinding;
import p325m0.MutabilityOwnership;

/* renamed from: jp.pxv.android.activity.PixivisionActivity */
/* loaded from: classes2.dex */
public class PixivisionActivity extends AbstractActivityC0120m2 {

    /* renamed from: e0 */
    public static final /* synthetic */ int f18509e0;

    /* renamed from: b0 */
    public ActivityPixivisionRenewalBinding f18510b0;

    /* renamed from: c0 */
    public Pixivision f18511c0;

    /* renamed from: d0 */
    public final PixivAppUserAgents f18512d0 = (PixivAppUserAgents) C2518n.m7641d(PixivAppUserAgents.class);

    /* renamed from: jp.pxv.android.activity.PixivisionActivity$a */
    /* loaded from: classes2.dex */
    public class C4056a extends WebViewClient {

        /* renamed from: a */
        public final /* synthetic */ Map f18513a;

        public C4056a(Map map) {
            PixivisionActivity.this = r1;
            this.f18513a = map;
        }

        /* renamed from: a */
        public final boolean m4773a(Uri uri) {
            String host = uri.getHost();
            if (host.contains("pixivision.net") || host.contains("spotlight.pics")) {
                PixivisionActivity.this.f18510b0.f22378u.loadUrl(uri.toString(), this.f18513a);
                return false;
            }
            try {
                PixivisionActivity.this.f18510b0.f22378u.getContext().startActivity(new Intent("android.intent.action.VIEW", uri));
            } catch (ActivityNotFoundException unused) {
                Toast.makeText(PixivisionActivity.this, (int) R.string.error_default_title, 1).show();
            }
            return true;
        }

        @Override // android.webkit.WebViewClient
        public void onPageFinished(WebView webView, String str) {
            ProgressBar progressBar = PixivisionActivity.this.f18510b0.f22375r;
            if (progressBar != null) {
                progressBar.setVisibility(8);
            }
        }

        @Override // android.webkit.WebViewClient
        public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
            ProgressBar progressBar = PixivisionActivity.this.f18510b0.f22375r;
            if (progressBar != null) {
                progressBar.setProgress(0);
                PixivisionActivity.this.f18510b0.f22375r.setVisibility(0);
            }
            PixivisionActivity.this.f18510b0.f22377t.setScrollY(0);
        }

        @Override // android.webkit.WebViewClient
        public boolean shouldOverrideUrlLoading(WebView webView, String str) {
            return m4773a(Uri.parse(str));
        }

        @Override // android.webkit.WebViewClient
        @TargetApi(24)
        public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
            return m4773a(webResourceRequest.getUrl());
        }
    }

    /* renamed from: jp.pxv.android.activity.PixivisionActivity$b */
    /* loaded from: classes2.dex */
    public class C4057b extends WebChromeClient {
        public C4057b() {
            PixivisionActivity.this = r1;
        }

        @Override // android.webkit.WebChromeClient
        public void onProgressChanged(WebView webView, int i) {
            ProgressBar progressBar = PixivisionActivity.this.f18510b0.f22375r;
            if (progressBar != null) {
                progressBar.setProgress(i);
            }
        }

        @Override // android.webkit.WebChromeClient
        public void onReceivedTitle(WebView webView, String str) {
            if (PixivisionActivity.this.m7044P0() != null) {
                PixivisionActivity.this.m7044P0().mo6929v(webView.getTitle());
            }
        }
    }

    /* renamed from: e1 */
    public static Intent m4774e1(Context context, Pixivision pixivision) {
        EdgeTreatment.m3909i(context);
        EdgeTreatment.m3909i(pixivision);
        Intent intent = new Intent(context, PixivisionActivity.class);
        intent.putExtra("PIXIVISION", pixivision);
        return intent;
    }

    @Override // p270jp.pxv.android.activity.AbstractActivityC4151b, p270jp.pxv.android.activity.BaseActivity, androidx.fragment.app.FragmentActivity, androidx.activity.ComponentActivity, p248j2.ActivityC3902g, android.app.Activity
    @SuppressLint({"SetJavaScriptEnabled"})
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.f18510b0 = (ActivityPixivisionRenewalBinding) DataBindingUtil.m11369d(this, R.layout.activity_pixivision_renewal);
        this.f18757A.m6525e(AnalyticsScreenName.PIXIVISION_DETAIL);
        String str = "";
        C1124a.m10196R(this, this.f18510b0.f22376s, str);
        Intent intent = getIntent();
        if (intent.hasExtra("PIXIVISION")) {
            Pixivision pixivision = (Pixivision) intent.getSerializableExtra("PIXIVISION");
            this.f18511c0 = pixivision;
            str = pixivision.getArticleUrl();
        } else if (intent.hasExtra("PIXIVISION_URL")) {
            str = intent.getStringExtra("PIXIVISION_URL");
        }
        HashMap hashMap = new HashMap();
        hashMap.put("Accept-Language", Locale.getDefault().toString());
        this.f18510b0.f22378u.setWebViewClient(new C4056a(hashMap));
        this.f18510b0.f22378u.setWebChromeClient(new C4057b());
        this.f18510b0.f22378u.getSettings().setJavaScriptEnabled(true);
        WebSettings settings = this.f18510b0.f22378u.getSettings();
        settings.setUserAgentString(this.f18510b0.f22378u.getSettings().getUserAgentString() + " " + this.f18512d0.f5005b);
        this.f18510b0.f22378u.setOnKeyListener(View$OnKeyListenerC0136p6.f528a);
        this.f18510b0.f22378u.loadUrl(str, hashMap);
    }

    @Override // androidx.activity.ComponentActivity, android.app.Activity
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_pixivision, menu);
        if (this.f18511c0 != null) {
            return true;
        }
        menu.removeItem(R.id.menu_share_pixivision);
        return true;
    }

    @Override // p270jp.pxv.android.activity.AbstractActivityC4151b, androidx.activity.ComponentActivity, android.app.Activity
    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() != R.id.menu_share_pixivision) {
            return super.onOptionsItemSelected(menuItem);
        }
        this.f18757A.m6527c(8, AnalyticsAction.PIXIVISION_SHARE, this.f18511c0.getArticleUrl());
        Pixivision pixivision = this.f18511c0;
        String format = String.format("%s | pixivision %s", pixivision.getTitle(), pixivision.getArticleUrl());
        MutabilityOwnership.m3745m(format, "shareText");
        Intent intent = new Intent("android.intent.action.SEND");
        intent.setType("text/plain");
        intent.putExtra("android.intent.extra.TEXT", format);
        startActivity(Intent.createChooser(intent, null));
        return true;
    }
}
